package com.sl.boot.admindemo.domain.drugOrder.service.impl;

import com.sl.boot.admindemo.domain.drugOrder.entity.DrugOrder;
import com.sl.boot.admindemo.dao.DrugOrderDao;
import com.sl.boot.admindemo.domain.drugOrder.service.DrugOrderService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (DrugOrder)表服务实现类
 *
 * @author makejava
 * @since 2022-06-19 20:04:30
 */
@Service("drugOrderService")
public class DrugOrderServiceImpl implements DrugOrderService {
    @Resource
    private DrugOrderDao drugOrderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DrugOrder queryById(Integer id) {
        return this.drugOrderDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param drugOrder   筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<DrugOrder> queryByPage(DrugOrder drugOrder, PageRequest pageRequest) {
        long total = this.drugOrderDao.count(drugOrder);
        return new PageImpl<>(this.drugOrderDao.queryAllByLimit(drugOrder, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param drugOrder 实例对象
     * @return 实例对象
     */
    @Override
    public DrugOrder insert(DrugOrder drugOrder) {
        this.drugOrderDao.insert(drugOrder);
        return drugOrder;
    }

    /**
     * 修改数据
     *
     * @param drugOrder 实例对象
     * @return 实例对象
     */
    @Override
    public DrugOrder update(DrugOrder drugOrder) {
        this.drugOrderDao.update(drugOrder);
        return this.queryById(drugOrder.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.drugOrderDao.deleteById(id) > 0;
    }
}
